package efu.nf.like.service.impl;

import efu.nf.like.common.enumeration.ErrorStatusEnum;
import efu.nf.like.common.exception.DataAccessException;
import efu.nf.like.mapper.UserMapper;
import efu.nf.like.model.entity.User;
import efu.nf.like.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lwj
 * @create 2025-10-12-17:02
 */
@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class UserServiceImpl implements UserService {
    private final UserMapper userMapper;

    @Override
    public User selectByUserName(String username) {
        User user = userMapper.selectByUserName(username);
        if(user == null){
            log.error("用户不存在");
            throw new DataAccessException(ErrorStatusEnum.USER_NOT_EXIST);
        }
        return user;
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void insert(User user) {
        userMapper.insert(user);
    }

    @Override
    public void delete(Integer userId) {
        userMapper.delete(userId);
    }
}
